﻿using System;
using System.Linq;
using System.Web.Mvc;
using ilgolosone.DomainModel.Entities;
using ilgolosone.DomainModel.Queries;
using ilgolosone.DomainModel.Repositories;
using ilgolosone.UI.Extensibility.ActionFilters;
using ilgolosone.UI.Models;

namespace ilgolosone.UI.Controllers
{
    [HandleError]
    public class HomeController : SmartController
    {
        private readonly ISpecialtyRepository _specialtyRepository;

        public HomeController(ISpecialtyRepository specialtyRepository)
        {
            _specialtyRepository = specialtyRepository;
        }

        [ConsumeUnitOfWork]
        [MapObjects(typeof(Specialty[]),typeof(SpecialtyView[]))]
        public ActionResult Index()
        {            
            ViewData.Model = _specialtyRepository.ToArray();

            return View();
        }

        [ConsumeUnitOfWork]
        [MapObjects(typeof(Specialty[]), typeof(SpecialtyView[]))]
        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult SearchSpecialtyByName(string searchBox)
        {
            var specialtiesQuery = new FindSpecialtyByPartOfName(searchBox);

            Specialty[] specialties = _specialtyRepository.Filter(specialtiesQuery).ToArray();

            ViewData.Model = specialties;
            
            return View("Index");
        }


        [ConsumeUnitOfWork]
        [MapObjects(typeof(Restaurant[]), typeof(RestaurantView[]))]
        public ActionResult Reserve(Guid restaurantId)
        {
            
            return View();
        }

        [ConsumeUnitOfWork]
        [MapObjects(typeof(Restaurant[]), typeof(RestaurantView[]))]
        public ActionResult RestaurantBySpecialty(Guid id)
        {
            ViewData.Model = _specialtyRepository.GetRestaurantBySpecialties(id);
            //ViewData.Model = _specialtyRepository.ToArray();

            return View();
        }
    }
}
